package com.jihox.abookpro.util;

import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
/**
 * 
 * @author devin.chen
 * 文本框输入监听
 * 有值则显示清除按钮，否则隐藏
 */
public class MyTextWatcher implements TextWatcher {
	private Button resetbtn;
	private boolean isvisible = false;
	public MyTextWatcher(){
		
	}
	
	public MyTextWatcher(Button resetbtn){
		this.resetbtn = resetbtn;
	}

	@Override
	public void afterTextChanged(Editable s) {
		// TODO Auto-generated method stub

	}

	@Override
	public void beforeTextChanged(CharSequence s, int start, int count,
			int after) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onTextChanged(CharSequence s, int start, int before, int count) {
		if(s.length()>0){
			if(!isvisible){
				resetbtn.setVisibility(View.VISIBLE);
				isvisible = true;
			}
		}else{
			if(isvisible){
				resetbtn.setVisibility(View.INVISIBLE);
				isvisible = false;
			}
		}
	}

}
